/* 
 *  javascribd - Java client library for the Scribd API. 
 *  Copyright (C) 2009 by Marcel Eyke, http://code.google.com/p/javascribd/ 
 *  Use is subject to license terms of LGPL. See license.txt. 
 */
package com.google.code.javascribd.type;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.activation.MimetypesFileTypeMap;

import com.google.code.javascribd.connection.StreamableData;

public class FileData implements StreamableData {
	/* TODO, May 10, 2009, meyke - do it constant and thread save */
	private MimetypesFileTypeMap mimeTypeMap = new MimetypesFileTypeMap();
	private File file;

	public FileData(File file) {
		super();
		if (file == null) {
			throw new IllegalArgumentException("file must be not null");
		}
		this.file = file;
	}

	public File getFile() {
		return file;
	}

	public InputStream getInputStream() throws IOException {
		return new FileInputStream(file);
	}

	public String getMimeType() {
		return mimeTypeMap.getContentType(file);
	}

	public String getName() {
		return file.getName();
	}
}
